<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>RTOS - a cooperative multitasking library: RTOS::mailbox&lt; T &gt; Class Template Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">RTOS - a cooperative multitasking library
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="class_r_t_o_s.html">RTOS</a>      </li>
      <li class="navelem"><a class="el" href="class_r_t_o_s_1_1mailbox.html">mailbox</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">RTOS::mailbox&lt; T &gt; Class Template Reference</div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="RTOS::mailbox" --><!-- doxytag: inherits="RTOS::mailbox_base" -->
<p>synchronous handling over of a data item  
 <a href="class_r_t_o_s_1_1mailbox.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for RTOS::mailbox&lt; T &gt;:</div>
<div class="dyncontent">
 <div class="center">
  <img src="class_r_t_o_s_1_1mailbox.png" usemap="#RTOS::mailbox&lt; T &gt;_map" alt=""/>
  <map id="RTOS::mailbox&lt; T &gt;_map" name="RTOS::mailbox&lt; T &gt;_map">
<area href="class_r_t_o_s_1_1mailbox__base.html" title="RTOS private implementation class." alt="RTOS::mailbox_base" shape="rect" coords="0,0,127,24"/>
</map>
 </div></div>

<p><a href="class_r_t_o_s_1_1mailbox-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mailbox.html#aaee470ef9fc6627e848e45ca353415ff">mailbox</a> (const char *name=&quot;&quot;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">construtor, specify mutex name  <a href="#aaee470ef9fc6627e848e45ca353415ff"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mailbox.html#ad140965320e8b42ca16a5d288858f70d">write</a> (const T item)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">write an item into the mailbox  <a href="#ad140965320e8b42ca16a5d288858f70d"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">T&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mailbox.html#af2bc862b64929b5ec34afa4dec0ed720">read</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">read a value from the mailbox  <a href="#af2bc862b64929b5ec34afa4dec0ed720"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><h3>template&lt;class T&gt;<br/>
class RTOS::mailbox&lt; T &gt;</h3>

<p>synchronous handling over of a data item </p>
<p>A mailbox is a template class synchronization mechanism. A single value can be written to the mailbox. Another task can read the value from the mailbox. The read and write calls each wait on each other before they are allowed to proceed. A mailbox is not created for a particular task, and it is not a waitable.</p>
<p>Initially a mailbox is empty. The <a class="el" href="class_r_t_o_s_1_1mailbox.html#ad140965320e8b42ca16a5d288858f70d">write()</a> operation bloks the calling task until the mailbox is empty, then writes to the mailbox, and blocks. The <a class="el" href="class_r_t_o_s_1_1mailbox.html#af2bc862b64929b5ec34afa4dec0ed720">read()</a> operation blocks the calling task until there is a value in the mailbox. Then it reads the value, unblocks the task that wrote to the mailbox, and returns.</p>
<p>The example below uses a mailbox to buffer writing cout data to the UART. The function that writes each cout character writes it to a mailbox, which is read by the UART task. This task waits 2 MS after each write to the UART, to avoid busy waiting.</p>
<div class="fragment"><pre class="fragment"> TBW
</pre></div> </div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="aaee470ef9fc6627e848e45ca353415ff"></a><!-- doxytag: member="RTOS::mailbox::mailbox" ref="aaee470ef9fc6627e848e45ca353415ff" args="(const char *name=&quot;&quot;)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class T &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_r_t_o_s_1_1mailbox.html">RTOS::mailbox</a>&lt; T &gt;::<a class="el" href="class_r_t_o_s_1_1mailbox.html">mailbox</a> </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em> = <code>&quot;&quot;</code></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>construtor, specify mutex name </p>
<p>Create a mutex. The mutex is initially set. The template argument T must be a class that has a non-arguments constructor and supports assignment. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="af2bc862b64929b5ec34afa4dec0ed720"></a><!-- doxytag: member="RTOS::mailbox::read" ref="af2bc862b64929b5ec34afa4dec0ed720" args="(void)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class T &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">T <a class="el" href="class_r_t_o_s_1_1mailbox.html">RTOS::mailbox</a>&lt; T &gt;::read </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>read a value from the mailbox </p>
<p>If one or more tasks are waiting for the mutex the first one is released, and it now owns the mutex. Otherwise, if the mutex is cleared it is now set.</p>
<p>It is an error for a task to call signal() on a mutex that it does not own (that it did not call wait() on). After the signal the task no longer owns the mutex. </p>

</div>
</div>
<a class="anchor" id="ad140965320e8b42ca16a5d288858f70d"></a><!-- doxytag: member="RTOS::mailbox::write" ref="ad140965320e8b42ca16a5d288858f70d" args="(const T item)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class T &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_r_t_o_s_1_1mailbox.html">RTOS::mailbox</a>&lt; T &gt;::write </td>
          <td>(</td>
          <td class="paramtype">const T&#160;</td>
          <td class="paramname"><em>item</em></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>write an item into the mailbox </p>
<p>If the mutex was set it it is now cleared, and the calling task owns the mutex.</p>
<p>Otherwise the current task waits (is halted) until the owning task calls signal() on the same mutex. The signal() calls will release the tasks in the order of their wait() calls. </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a></li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Apr 14 2012 15:59:31 for RTOS - a cooperative multitasking library by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
